import { createRouter, createWebHistory } from 'vue-router'

export const routerFiles = import.meta.glob('../views/**/index.vue')
const routeList = []
const upperName = name => name.split('/').map(da => da.replace(/^\w/g, d => d.toUpperCase())).join('')
for (const [key, component] of Object.entries(routerFiles)) {
  const path = key.replace('../views', '').replace('/index.vue', '')
  const isEdit = path.indexOf('/edit') > -1
  if (isEdit) {
    routeList.push({
      path: isEdit ? path.replace('/edit', '/NEW') : path,
      name: upperName(path.replace('edit', 'New').replace('/', '')),
      component,
      props: isEdit,
      hidden: isEdit,
      meta: {}
    })
  }
  routeList.push({
    path: isEdit ? path.replace('/edit', '/edit/:id') : path,
    name: upperName(path.replace('/', '')),
    component,
    props: isEdit,
    hidden: isEdit,
    meta: {}
  })
}

export const routes = routeList

console.log('wms routes', routes)
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})
export default router